<?php
namespace App\Socket\Logic;
use EasySwoole\Core\Swoole\ServerManager;
use EasySwoole\Core\Swoole\Task\TaskManager;

use App\Socket\Model\User;
use App\Socket\Model\Room;



class Base{
    public static function notice($obj,Room $room){
        $str = json_encode($obj);                               
        $users = $room->Users;      
        TaskManager::async((function()use($str,$users){
            foreach($users as $item){
                ServerManager::getInstance()->getServer()->push($item->fd,$str);
            }
        }));   
    }

    public static function push($fd,$obj){
        $str = json_encode($obj);
        ServerManager::getInstance()->getServer()->push($fd,$str);        
    }

    public static function closeFd($fd){
        ServerManager::getInstance()->getServer()->close($fd);                              
    }

    /** 检测Fd连接是否存在 */
    public static function checkFd($fd){
        return ServerManager::getInstance()->getServer()->exist($fd);                    
    }

}